﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MovieRental.DataInterfaces;
using MovieRental.Entities;
using MovieRental.GeneralDataExceptions;
using MovieRental.XmlDataProviderCore;

namespace MovieRental.XmlRepositoryLibrary
{
    public class XmlCartDiscountRepository : XmlRepository<CartDiscountInfo>, ICartDiscountRepository
    {
        public XmlCartDiscountRepository(XmlDataProvider provider)
            :base(provider)
        {     
        }

        public CartDiscountInfo Load(Guid id)
        {
            using (var context = CreateContext())
            {
                var set = context.GetAllForType(typeof(CartDiscountInfo)).Select(x => (CartDiscountInfo)x);
                try
                {
                    return set.Single(x => x.Id == id);
                }
                catch (Exception ex)
                {
                    throw new ItemNotFoundException(id.ToString(), ex);
                }
            }
        }

        public void Delete(Guid id)
        {
            CartDiscountInfo cartDiscount = new CartDiscountInfo(id);
            Delete(cartDiscount);
        }
    }
}
